package interceptor;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import entity.Employee;

/**
 * @author 陈彬彬
 * @publish 2015-11-6 下午9:55:40
 * @category 权限管理拦截器
 */
public class PowerInterceptor extends MethodFilterInterceptor {


	@Override
	protected String doIntercept(ActionInvocation arg0) throws Exception {
		//通过servlet api方式获取session对象
				HttpSession session=ServletActionContext.getRequest().getSession();
				Employee user=(Employee) session.getAttribute("user");
				if(user==null){
					//自定义方式将数据保存到request请求域中，会在页面获取到该数据
					ServletActionContext.getRequest().setAttribute("msg", "您尚未登录！请先登录");
					return "nologin";
				}
				return arg0.invoke();//继续调用目标的拦截器或Action
	}

}
